var config = require('config-lite');
var moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  var Signlog = sequelize.define('signlog', {
    uuid: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true
    },
    area_uuid: {
      type: DataTypes.UUID
    },
    user_uuid: {
      type: DataTypes.UUID
    },
    time: {
      type: DataTypes.DATE,
      defaultValue: new Date(),
      get: function () {
        return moment(this.getDataValue('time')).format('YYYY-MM-DD HH:mm:ss') || null;
      }
    },
    staff_uuid: {
      type: DataTypes.UUID
    },
    event_uuid: {
      type: DataTypes.UUID
    }
  }, {
    // 是否需要增加created_at、updated_at、deleted_at字段
    timestamps: true,
    underscored: true,
    // 设置paranoid为true（此种模式下，删除数据时不会进行物理删除，而是设置deleted_at为当前时间
    paranoid: true
  });

  Signlog.associate = function(models) {
    // Using additional options like CASCADE etc for demonstration
    // Can also simply do Task.belongsTo(models.User);
    // User.belongsTo(models.xxx, {
    //   // onDelete: 'CASCADE',
    // });
    Signlog.belongsTo(models.area, {
      // onDelete: 'CASCADE',
    });

    Signlog.belongsTo(models.user, {
      // onDelete: 'CASCADE',
    });

    Signlog.belongsTo(models.staff, {
      // onDelete: 'CASCADE',
    });

    Signlog.belongsTo(models.event, {
      // onDelete: 'CASCADE',
    });
  };

  return Signlog;
};
